!! Copyright (C) 2009,2010,2011,2012  Marco Restelli
!!
!! This file is part of:
!!   LDGH -- Local Hybridizable Discontinuous Galerkin toolkit
!!
!! LDGH is free software: you can redistribute it and/or modify it
!! under the terms of the GNU General Public License as published by
!! the Free Software Foundation, either version 3 of the License, or
!! (at your option) any later version.
!!
!! LDGH is distributed in the hope that it will be useful, but WITHOUT
!! ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
!! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
!! License for more details.
!!
!! You should have received a copy of the GNU General Public License
!! along with LDGH. If not, see <http://www.gnu.org/licenses/>.
!!
!! author: Marco Restelli                   <marco.restelli@gmail.com>


!>\brief
!!
!! Dummy version of \c mod_mumpsintf to avoid linking MUMPS.
!!
!! \n
!!
!! The constructor, destructor and clean functions can be called,
!! while the remaining function return an error. The use statements
!! are the same as in the true module, to simplify debugging and
!! testing with and without MUMPS.
!<----------------------------------------------------------------------
module mod_mumpsintf

!-----------------------------------------------------------------------

 use mod_messages, only: &
   mod_messages_initialized, &
   error,   &
   warning, &
   info

 use mod_kinds, only: &
   mod_kinds_initialized, &
   wp

 use mod_sparse, only: &
   mod_sparse_initialized, &
   t_col, t_tri,&
   col2tri,     &
   clear

 use mod_mpi_utils, only: &
   mod_mpi_utils_initialized, &
   mpi_reduce, wp_mpi, mpi_sum, &
   mpi_bcast

!-----------------------------------------------------------------------
 
 implicit none

!-----------------------------------------------------------------------

! Module interface

 public :: &
   mod_mumpsintf_constructor, &
   mod_mumpsintf_destructor,  &
   mod_mumpsintf_initialized, &
   mumps_factor, &
   mumps_solve,  &
   mumps_clean,  &
   distributed

 private

!-----------------------------------------------------------------------

 ! Public variables to control the solver
 logical, target :: distributed

 logical, protected :: &
   mod_mumpsintf_initialized = .false.
 character(len=*), parameter :: &
   errormsg = &
     'This is not a real MUMPS interface and should not be called.'
 character(len=*), parameter :: &
   this_mod_name = 'mod_mumpsintf_dummy'

!-----------------------------------------------------------------------

contains

!-----------------------------------------------------------------------

 subroutine mod_mumpsintf_constructor()
  character(len=*), parameter :: &
    this_sub_name = 'constructor'

   !Consistency checks ---------------------------
   if( (mod_messages_initialized.eqv..false.) .or. &
          (mod_kinds_initialized.eqv..false.) .or. &
         (mod_sparse_initialized.eqv..false.) .or. &
      (mod_mpi_utils_initialized.eqv..false.) ) then
     call error(this_sub_name,this_mod_name, &
                'Not all the required modules are initialized.')
   endif
   if(mod_mumpsintf_initialized.eqv..true.) then
     call warning(this_sub_name,this_mod_name, &
                  'Module is already initialized.')
   endif
   !----------------------------------------------

   mod_mumpsintf_initialized = .true.
 end subroutine mod_mumpsintf_constructor

!-----------------------------------------------------------------------
 
 subroutine mod_mumpsintf_destructor()
  character(len=*), parameter :: &
    this_sub_name = 'destructor'
   
   !Consistency checks ---------------------------
   if(mod_mumpsintf_initialized.eqv..false.) then
     call error(this_sub_name,this_mod_name, &
                'This module is not initialized.')
   endif
   !----------------------------------------------

   mod_mumpsintf_initialized = .false.
 end subroutine mod_mumpsintf_destructor

!-----------------------------------------------------------------------

 subroutine mumps_factor(m,gn,gij,comm)
  type(t_col), intent(in) :: m
  integer, optional, intent(in) :: &
    gn, gij(:), comm
 
  character(len=*), parameter :: &
    this_sub_name = 'mumps_factor'

   call error(this_sub_name,this_mod_name,errormsg)
 
 end subroutine mumps_factor
 
!-----------------------------------------------------------------------
 
 subroutine mumps_solve(m,x,y,transposed_mat,comm)
  type(t_col), intent(in) :: m
  real(wp),    intent(in) :: y(:)
  real(wp),   intent(out) :: x(:)
  logical, optional, intent(in) :: transposed_mat
  integer, optional, intent(in) :: comm

  character(len=*), parameter :: &
    this_sub_name = 'mumps_solve'

   call error(this_sub_name,this_mod_name,errormsg)
 
 end subroutine mumps_solve
 
!-----------------------------------------------------------------------
 
 subroutine mumps_clean()
  character(len=*), parameter :: &
    this_sub_name = 'mumps_clean'

   ! nothing to do
 
 end subroutine mumps_clean
 
!-----------------------------------------------------------------------

end module mod_mumpsintf

